<template>
  <div class="container">
    <el-dialog
      title="提示"
      :visible="value"
      @close="closeDialog"
      width="30%"
    >
    <el-alert v-if="type=='del'" title="此操作将永久删除该题目, 是否继续?" type="warning" show-icon :closable="false"></el-alert>
    <el-alert v-else-if="type=='add'" title="此操作将该题目加入精选, 是否继续?" type="info" show-icon :closable="false"></el-alert>
    <el-alert v-else-if="type=='pub'"  type="warning" show-icon :closable="false">
      <template #default>
        你确认{{ publish.publishState == 0?'上架':'下架' }}这道题吗?
      </template>

    </el-alert>

      <span slot="footer" class="dialog-footer">
        <el-button @click="closeDialog()">取 消</el-button>
        <el-button type="primary" @click="closeDialog(id,type)"
          >确 定</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { remove, choiceAdd, choicePublish } from '@/api/hmmm/questions.js'
export default {
  name: 'questionOperateDialog',
  props: {
    // 接受id
    id: {
      type: [Number, String],
      required: true
    },
    value: {
      type: [String, Boolean],
      required: true
    },
    type: {
      type: [String],
      required: true
    },
    publish: {
      type: [Object],
      required: true
    }
  },
  data () {
    return {
      questionDetail: {}
    }
  },
  created () {

  },
  methods: {
    // 关闭弹出框函数
    async closeDialog (id, type) {
      // 如果是del走删除分支
      if (type === 'del') {
        await remove({ id: id })
        this.$message.success('删除成功')
        this.$emit('updata')
      }
      if (type === 'add') {
        await choiceAdd({
          id: id,
          choiceState: 1
        })
        this.$message.success('已加入精选')
        this.$emit('updata')
      }
      if (type === 'pub') {
        if (this.publish.publishState === 0) {
          this.publish.publishState = 1
          await choicePublish(this.publish)
          this.$message.success('上架成功')
        } else {
          this.publish.publishState = 0
          await choicePublish(this.publish)
          this.$message.success('下架成功')
        }
        this.$emit('updata')
      }
      this.$emit('input', false)
    }

  }
}
</script>

 <style scoped lang='scss'>

 .el-dialog__header {
    background-color: #fff;
 }
.el-alert {
    background-color: #fff;
    color: #333;
    font-size: 16px;
}
</style>
